{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abcdefghijklmnopqrstuvwxyz\n",
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
      "0123456789\n",
      "0123456789abcdefABCDEF\n",
      "01234567\n",
      "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n",
      "\r",
      "\u000b",
      "\f",
      "\n",
      "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\n"
     ]
    }
   ],
   "source": [
    "# Generating a random string.\n",
    "# https://pythontips.com/2013/07/28/generating-a-random-string/\n",
    "\n",
    "# python uuid documentation\n",
    "# https://docs.python.org/3/library/uuid.html\n",
    "# UUID —— Universally Unique IDentifier\n",
    "# GUID —— Globally Unique IDentifier     \n",
    "\n",
    "# UUID的算法介绍：《A Universally Unique IDentifier (UUID) URN Namespace》\n",
    "# https://www.ietf.org/rfc/rfc4122.txt\n",
    "\n",
    "\n",
    "import random\n",
    "import string\n",
    "\n",
    "def random_generator(size=6, chars=string.ascii_letters+ string.digits):\n",
    "    return ''.join(random.choice(chars) for x in range(size))\n",
    "\n",
    "print(string.ascii_lowercase)  # abcdefghijklmnopqrstuvwxyz\n",
    "print(string.ascii_uppercase)  # ABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
    "print(string.ascii_letters)  # abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
    "print(string.digits)  # 0123456789\n",
    "print(string.hexdigits)  # 0123456789abcdefABCDEF\n",
    "print(string.octdigits)  # 01234567\n",
    "print(string.printable)  # 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \n",
    "print(string.punctuation)  # !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "Capital = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\",\n",
    "           \"W\", \"X\", \"Y\", \"Z\"]\n",
    "Letter = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\",\n",
    "          \"w\", \"x\", \"y\", \"z\"]\n",
    "Character = [\"~\", \"!\", \"@\", \"#\", \"￥\", \"$\", \"%\", \"^\", \"&\", \"*\", \"(\", \")\", \"_\", \"-\", \"+\", \"=\", \"{\", \"[\", \"]\", \"}\", \";\",\n",
    "             \":\", \"'\", \",\", \".\", \"/\", \"<\", \">\", \"?\", \"~\", \"《\", \"》\", \"|\", \"”\", \"“\"]\n",
    "Strings = [\"赵\", \"钱\", \"孙\", \"李\", \"周\", \"吴\", \"郑\", \"王\", \"冯\", \"陈\", \"褚\", \"卫\", \"蒋\", \"沈\", \"韩\", \"杨\", \"朱\", \"秦\", \"尤\",\n",
    "           \"许\", \"何\", \"吕\", \"施\", \"张\", \"孔\", \"曹\", \"严\", \"华\", \"金\", \"魏\", \"陶\", \"姜\", \"戚\", \"谢\", \"邹\", \"喻\", \"柏\", \"水\",\n",
    "           \"窦\", \"章\", \"暨\", \"居\", \"衡\", \"步\", \"都\", \"耿\", \"满\", \"弘\", \"云\", \"苏\", \"潘\", \"葛\", \"匡\", \"国\", \"文\", \"寇\", \"奚\",\n",
    "           \"范\", \"彭\", \"郎\", \"广\", \"禄\", \"阙\", \"东\", \"鲁\", \"韦\", \"昌\", \"马\", \"苗\", \"凤\", \"花\", \"方\", \"俞\", \"任\", \"袁\", \"柳\",\n",
    "           \"酆\", \"鲍\", \"史\", \"唐\", \"费\", \"廉\", \"岑\", \"薛\", \"雷\", \"贺\", \"倪\", \"汤\", \"滕\", \"殷\", \"罗\", \"毕\", \"郝\", \"邬\", \"安\",\n",
    "           \"常\", \"乐\", \"于\", \"时\", \"傅\", \"米\", \"贝\", \"明\", \"臧\", \"贾\", \"路\", \"娄\", \"危\", \"虞\", \"万\", \"支\", \"柯\", \"包\", \"诸\",\n",
    "           \"左\", \"石\", \"芮\", \"羿\", \"储\", \"靳\", \"皮\", \"卞\", \"齐\", \"康\", \"计\", \"伏\", \"成\", \"戴\", \"江\", \"童\", \"颜\", \"郭\", \"昝\",\n",
    "           \"管\", \"卢\", \"莫\", \"崔\", \"吉\", \"钮\", \"龚\", \"汲\", \"邴\", \"糜\", \"松\", \"伍\", \"余\", \"元\", \"卜\", \"谈\", \"宋\", \"茅\", \"庞\",\n",
    "           \"梅\", \"盛\", \"林\", \"刁\", \"经\", \"房\", \"裘\", \"缪\", \"程\", \"嵇\", \"邢\", \"滑\", \"井\", \"段\", \"富\", \"巫\", \"顾\", \"孟\", \"平\",\n",
    "           \"黄\", \"熊\", \"纪\", \"舒\", \"屈\", \"钟\", \"徐\", \"邱\", \"骆\", \"干\", \"解\", \"应\", \"宗\", \"裴\", \"陆\", \"荣\", \"翁\", \"乌\", \"焦\",\n",
    "           \"巴\", \"弓\", \"和\", \"穆\", \"萧\", \"尹\", \"项\", \"祝\", \"董\", \"梁\", \"高\", \"夏\", \"蔡\", \"田\", \"丁\", \"宣\", \"贲\", \"邓\", \"荀\",\n",
    "           \"羊\", \"於\", \"惠\", \"牧\", \"隗\", \"山\", \"谷\", \"姚\", \"邵\", \"湛\", \"汪\", \"杜\", \"阮\", \"蓝\", \"闵\", \"樊\", \"胡\", \"凌\", \"霍\",\n",
    "           \"郁\", \"单\", \"杭\", \"洪\", \"甄\", \"曲\", \"家\", \"封\", \"车\", \"侯\", \"宓\", \"蓬\", \"师\", \"巩\", \"厍\", \"聂\", \"晁\", \"勾\", \"敖\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "0.7534389342895449\n",
      "1.4005850287010484\n",
      "o\n",
      "41\n",
      "[6, 3, 7, 5, 1]\n",
      "['i', 'b', 'q', 'r', 'l']\n",
      "A-i-L-q-d-W-p-M\n",
      "v-o-r-x-f\n",
      "布\n",
      "former [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]\n",
      "later [7, 8, 4, 0, 2, 3, 1, 6, 5, 9]\n"
     ]
    }
   ],
   "source": [
    "# python random\n",
    "# http://www.runoob.com/python/func-number-random.html\n",
    "\n",
    "import random\n",
    "\n",
    "print( random.randint(1,10) )        # 产生 1 到 10 的一个整数型随机数  \n",
    "print( random.random() )             # 产生 0 到 1 之间的随机浮点数\n",
    "print( random.uniform(1.1,5.4) )     # 产生  1.1 到 5.4 之间的随机浮点数，区间可以不是整数\n",
    "print( random.choice('tomorrow') )   # 从序列中随机选取一个元素\n",
    "print( random.randrange(1,100,2) )   # 生成从1到100的间隔为2的随机整数\n",
    "\n",
    "a=[1,3,5,6,7]                # 将序列a中的元素顺序打乱\n",
    "random.shuffle(a)\n",
    "print(a)\n",
    "\n",
    "# 多个字符中生成指定数量的随机字符：\n",
    "print(\n",
    "    random.sample('zyxwvutsrqponmlkjihgfedcba',5)\n",
    ")\n",
    "\n",
    "# 从a-zA-Z0-9生成指定数量的随机字符：\n",
    "ran_str = '-'.join(\n",
    "    random.sample(string.ascii_letters + string.digits, 8)\n",
    ")\n",
    "print(ran_str)\n",
    "\n",
    "# 多个字符中选取指定数量的字符组成新字符串：\n",
    "print(\n",
    "    '-'.join(\n",
    "        random.sample( ['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5)\n",
    "    )\n",
    ")\n",
    "\n",
    "# 随机选取字符串：\n",
    "print(random.choice(['剪刀', '石头', '布']))\n",
    "\n",
    "# 打乱排序\n",
    "items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]\n",
    "print('former', items)\n",
    "random.shuffle(items)\n",
    "print('later', items)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
